package cn.com.shinho.hg.core.config;

import cn.com.shinho.hg.core.base.controller.DefaultHGErrorAttributes;
import cn.com.shinho.hg.core.feign.HGFeignErrorDecoder;
import cn.com.shinho.hg.core.feign.HGFeignHeaderProcessInterceptor;
import feign.Feign;
import feign.Logger;
import feign.RequestInterceptor;
import feign.hystrix.HystrixFeign;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

/**
 * @program: hg-server-parent
 * @description: ${description}
 * @author: Mr.Ye
 * @create: 2018-08-02
 **/
@Configuration
@EnableFeignClients(basePackages = "cn.com.shinho")
public class DefaultFeignClientConfig {

    @Bean
    Logger.Level feignLoggerLevel() {
        return Logger.Level.FULL;
    }

    /**
     * feign请求加上当前请求接口的headers
     */
    @Bean
    public RequestInterceptor requestInterceptor() {
        return new HGFeignHeaderProcessInterceptor();
    }

    /**
     * 覆盖spring默认的响应消息格式
     */
    @Bean
    public DefaultHGErrorAttributes defaulthgErrorAttributes() {
        return new DefaultHGErrorAttributes();
    }

    /**
     * roses自定义错误解码器
     */
    @Bean
    @Scope("prototype")
    public Feign.Builder feignHystrixBuilder() {
        return HystrixFeign.builder().errorDecoder(new HGFeignErrorDecoder());
    }


}
